package com.cee.controller;

import com.cee.common.result.Result;
import com.cee.dto.OneTypeDTO;
import com.cee.model.OneType;
import com.cee.service.OneTypeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/oneType")
public class OneTypeController {

    @Autowired
    private OneTypeService oneTypeService;

    @PostMapping ("/list")
    public Result getList(@RequestBody OneTypeDTO oneTypeDTO){
        PageInfo pageInfo = oneTypeDTO.getPageInfo();
        Page<OneType> page = PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());

        oneTypeService.getOneTypeList();
        return Result.ok(new PageInfo<>(page));
    }


    @GetMapping ("/delete")
    public Result deleteOneType(Integer id){

        oneTypeService.deleteOneType(id);
        return Result.ok();
    }

    @PostMapping ("/add")
    public Result addOneType(@RequestBody OneType oneType){

        oneTypeService.saveOneType(oneType);
        return Result.ok();
    }

}
